#!/bin/bash

set -x
set -e

#https://npm.taobao.org/mirrors/node/v8.9.0/node-v8.9.0-linux-x64.tar.xz
node_ver=node-v8.9.0-linux-x64

if [ xreinstall == x"$1" ]; then
  rm -rf $node_ver.tar.xz $node_ver /usr/local/nodejs
fi

if [ ! -d /usr/local/nodejs ]; then
if [ ! -f $node_ver.tar.xz ]; then
  wget https://npm.taobao.org/mirrors/node/v8.9.0/$node_ver.tar.xz
fi

if [ ! -d $node_ver ]; then
  tar xvf $node_ver.tar.xz
fi

mv $node_ver /usr/local/nodejs
fi

rm -rf $node_ver.tar.xz

export NODE_HOME=/usr/local/nodejs
export PATH=$NODE_HOME/bin:$PATH

echo -e "export NODE_HOME=$NODE_HOME" >> ~/.bashrc
echo -e "export PATH=$NODE_HOME/bin:$PATH" >> ~/.bashrc

#npm config set registry https://registry.npm.taobao.org
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install -g vue-cli webpack grunt gitbook-cli loopback-cli

#npm install -g gulp node-gyp node-sass
#npm install --save-dev vue webpack
